package com.leizhi.demo.monitor.pojo;

import lombok.Data;

/**
 * @Description 通用返回结果
 * @Version 1.0.0-SNAPSHOT
 * @Author leizhi
 * @Date 2025/4/27 12:04
 */
@Data
public class WebResult {

    private Integer code;   // 编码：200-成功否则失败

    private String msg;     // 错误信息

    private Object data;    // 数据


    public static WebResult error(String msg) {
        WebResult result = new WebResult();
        result.code = 500;
        result.msg = msg;
        return result;
    }

    public static WebResult errorCode(String msg, int code) {
        WebResult result = new WebResult();
        result.code = code;
        result.msg = msg;
        return result;
    }

    public static WebResult errorWithData(String msg, int code, Object data) {
        WebResult result = new WebResult();
        result.code = code;
        result.msg = msg;
        result.data = data;
        return result;
    }

    public static WebResult successWithData(Object data) {
        WebResult result = new WebResult();
        result.code = 200;
        result.msg = "请求成功！";
        result.data = data;
        return result;
    }

    public static WebResult successWithData(String msg, Object data) {
        WebResult result = new WebResult();
        result.code = 200;
        result.msg = msg;
        result.data = data;
        return result;
    }

    public static WebResult successWithoutData(String msg) {
        WebResult result = new WebResult();
        result.code = 200;
        result.msg = msg;
        return result;
    }

}
